package evolution.view;

import java.awt.Color;
import java.awt.Dimension;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 * 
 * @author camille
 */
public class Graph {

	private DefaultCategoryDataset dataset = new DefaultCategoryDataset();
	private JFreeChart chart;
	private ChartPanel chartPanel;
	private String title;

	public Graph(String title, String x, String y) {
		this.title = title;

		this.dataset = new DefaultCategoryDataset();

		this.chart = ChartFactory.createLineChart(this.title, x, y, dataset, PlotOrientation.VERTICAL, true, true, false);
		this.chart.setBackgroundPaint(Color.white);
		this.chart.getCategoryPlot().getRenderer().setSeriesPaint(0, new Color(0, 116, 255));

		this.chartPanel = new ChartPanel(chart);

		this.chartPanel.setPreferredSize(new Dimension(500, 270));
	}

	public ChartPanel getChartPanel() {
		return chartPanel;
	}

	public void addPoint(int t, double val) {
		this.dataset.addValue(val, this.title, String.valueOf(t));
	}

	public void clear() {
		this.dataset.clear();
	}
}
